package com.ljx.thread.thread03;

/**
 * @author LJX
 * @Description: TODO
 * @Date: 2022/11/1 9:43
 * @Version 1.0
 */
public class TestYield {
	public static void main(String[] args) {
		YieldThread yieldThread1 = new YieldThread();
		yieldThread1.start();


		for (int i = 0; i < 20; i++) {
			System.out.println(Thread.currentThread().getName()+"主线程");
		}
	}
}

class YieldThread extends Thread{
	@Override
	public void run() {
		for (int i = 0; i < 20; i++) {
			/**
			 * 让位，当前线程暂停，回到就绪状态，让给其它线程。
			 * 静态方法：Thread.yield();
			 */
			Thread.yield();
			System.out.println(Thread.currentThread().getName()+"~~~~~~~~~~~~~~");
		}
	}
}